﻿//Author:Michal Sporna
//License: https://operationsneakpeek.codeplex.com/license

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace World
{
    /// <summary>
    /// handles bomb interactions
    /// </summary>
    public static class BombHandler
    {
        #region properties
        public static bool PrepCompleted;
        public static bool StartShuffle;
        public static double TimeElapsedSinceWiresDrawn;
        public static bool CoverWires;//if true, all wires are being covered
        public static bool ShuffleDone;
        public static bool BombPass;//if right wire cut
        public static bool BombFail;//if wrong wire cut
        public static int NumberOfAttempts;//3 at the start
        public static bool ShowingBombFailInformation;
        #endregion

        #region public fields
        public static float BombFailedInformationAlphaRatio;
        public static float BombFailedInformationAlphaIncrementor;
        public static bool ShowingBombFailedInfo1; //bomb failed has 2 strings, 2 occur after 1st dissolves
        public static int ShuffleMoveNumber;
        public static bool DrawBombHeat;
        public static Rectangle WiresRect;//heat that is drawn around bomb wires when defusing
        #endregion

        #region private fields
        private static List<int> _AssignedIDs; //list of already assigned IDs
        
        private static bool _DefusingWireChosen;
        //private static double _TimeToSubtractOnBombFail;
    
        
        
        //SHUFFLING
        private static Vector2 _WireAOriginalPosition; //when moving 2 wires (shuffling) wireA is being moved to position of wireB, 
        private static Vector2 _WireBOriginalPosition; //but wireB'a pos is also changed as it moves to wireA's pos, then save original position of the wires
        private static bool _WireAFinishedShuffling;
        private static bool _WireBFinishedShuffling;
        private static string _WireColorA;
        private static string _WireColorB;
        private static bool Shuffling;
        private static bool _StartShuffleSet;
        //after wire cut (pass or fail)
        private static bool _BombPassProcessed;
        private static bool _ShowingBombFailedInfo1set; //just a helper
        private static bool _BombFailInformationShowed; //if false not yet showed, when there is wrong wire cut, then user is informed that  x attempts left, reshuffle will happen and time is subtracted
        private static bool _AllPositionsHaveBeenSet; //if all position of the wires have been determined, set it to true   
        //used for drawing the heat:
        private static int _HeatRectY;
        private static int _HeatRectHeight;
        private static int _HeatRectHeightModifier; //when the wire is cut, the heat becomes smaller and smaller, to build the tension
        private static bool _HeatHidden;
        private static bool _HeatLvl2Inited;

        private static bool _HeatRectCreated;
       

        private static Rectangle _HeatPowerUpHUD; //heat for powerup hud
        private static Rectangle _HeatPowerUpHUDSmall;
        
        //powerups
         private static bool _PowerUpsDrawn;

        //cancel button
         private static bool _CancelButtonPosSet;
         private static int[] _CancelButtonPos;

        #region TEXTURES
         private static bool _TexturesObtained;
         private static Texture2D _WireSlotEmptyTexture;
         private static Texture2D _PowerUpHUDTexture;
         private static Texture2D _PowerUpEmptySlotTexture;
         private static Texture2D _Heat3Texture;
         private static Texture2D _HeatTexture;
         private static Texture2D _Heat0Texture;
         private static Texture2D _CancelButtonTexture;

        #endregion

        #endregion



         #region methods


         #region PRIVATE

         /// <summary>
        /// Prepare powerup rectangles
        /// to be drawn
        /// </summary>
        /// <param name="powerupHUD"></param>
         private static void _PreparePowerupsToBeDrawn(Rectangle powerupHUD)
         {
             //declare
             int offset;
             SpriteFont fontface;

             try
             {
                 offset=30;
                 //get font face that all powerups use to display their current count
                 fontface = Util.Cache.GetFont("VerySmallFont").FontFace;

                 if (!_PowerUpsDrawn)
                 {
                     //create powerup rects
                     for (int i = 0; i < World.WorldManager.Powerups.Count; i++)
                     {
                         World.WorldManager.Powerups[i].Rect.X = powerupHUD.X + offset;
                         World.WorldManager.Powerups[i].Rect.Y = powerupHUD.Y + 70;
                         World.WorldManager.Powerups[i].Rect.Width = 60;
                         World.WorldManager.Powerups[i].Rect.Height = 60;
                         //get fontface for info about count of the powerup
                         World.WorldManager.Powerups[i].FontFace = fontface;

                         //create postiton for count info that is displayed next to the powerups slot
                         World.WorldManager.Powerups[i].CountInfoTextPosition = new Vector2(World.WorldManager.Powerups[i].Rect.X + World.WorldManager.Powerups[i].Rect.Width - 10, World.WorldManager.Powerups[i].Rect.Y + World.WorldManager.Powerups[i].Rect.Height - 15);

                         offset += 80;
                     }


                     _PowerUpsDrawn = true;
                 }


             }
             catch (Exception ex)
             {
                 Util.ErrorLogging.LogError(ex);

             }

         }

        /// <summary>
        /// randomly assigns an ID to the wire
        /// if ID is already taken
        /// then draw again
        /// </summary>
        /// <returns></returns>
        private static int _AssignRandomWireID(int difficulty, Util.Classes.BombWire currentlyBeingProcessedWire,int wiresCount,int index)
        {
            //declare
            int ID = -1;
            Random random;
         

            try
            {
                //if list holding assigned IDs is null, create
                if (_AssignedIDs == null)
                {
                    //create new instance first
                    _AssignedIDs = new List<int>();
                

                    _DefusingWireChosen = false;
                  

                    
                }

                //randomly assign id to the currently being processed wire
                random = new Random();

                //keep assigning until ID is different from current wire index
                ID = GetTheRandomNumber();

                if (ID == index)
                {
                    while (ID == index)
                    {
                        ID = GetTheRandomNumber(); //from wire count subtract 1; from that subtract number of already assigned wires to eliminate already assigned ids
                    }
                }

                if (ID > wiresCount-1)
                {
                    while (ID > wiresCount-1)
                    {
                        ID /= wiresCount;
                    }
                }

                //if drawn ID is already assigned, then draw again
                if (_AssignedIDs.Contains(ID))
                {
                    while (_AssignedIDs.Contains(ID))
                    {
                        //keep assigning until ID that has not been assigned yet is drawn
                        ID = GetTheRandomNumber();

                        if (ID > wiresCount - 1)
                        {
                            while (ID > wiresCount - 1)
                            {
                                ID /= wiresCount;
                            }
                        }

                    };
                    //add to the list 
                    _AssignedIDs.Add(ID);
                }
                else
                {
                    _AssignedIDs.Add(ID);
                }



                

                //return wire's ID
                return ID;
            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);
                return -1;
            }


        }

        /// <summary>
        /// make random ID, more ranodm
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        private static int CustomizeID(int ID, int wiresCount)
        {
           

            try
            {
                ID -= 1;

                if (ID< 0)
                {
                    ID += 1;
                }

                if (ID > wiresCount)
                {
                    ID = -1;
                }


                return ID;
            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);
                return -1;
            }
        }

        /// <summary>
        /// set defusing wire
        /// </summary>
        private static void SetDefusingWire()
        {
            //declare
            Random random=new Random();
            int decision;

            try
            {

                //see if this wire is defusing (random decision)
                //only if not assigned yet
                if (!_DefusingWireChosen)
                {
                    decision = _AssignedIDs[random.Next(_AssignedIDs.Count)];

                    


                    //get wire colors of the bomb
                   
                            //set _time to subtract so later on we don't have to loop agian
                            //_TimeToSubtractOnBombFail = Levels.LevelManager.CurrentMap.AvailableBombs[i].TimeToSubtractOnBombFailed;

                            //loop through wires and assign random IDs , which is basically a place where it'g oging to be displayed
                    for (int w = 0; w < World.WorldManager.BombInstanceBeingDefused.Wires.Count; w++)
                            {
                              
                                //assign random id
                                if (World.WorldManager.BombInstanceBeingDefused.Wires[w].ID == decision)
                                {
                                    //assign isDefusingWire property to true
                                    World.WorldManager.BombInstanceBeingDefused.Wires[w].DefusingWire = true;
                                    _DefusingWireChosen = true;
                                    break;
                                }
                            }

                          
                        
                    


                }


            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);
                return;
            }

        }

       


        /// <summary>
        /// from 10 numbers randomly drawn
        /// get 1 that occurs the most and is the lowest
        /// </summary>
        /// <returns></returns>
        private static int GetTheRandomNumber()
        {
            //declare
            int[] drawnNumbers;
            int countNumbers = 0;
            int biggestOccurence = 0;
            int biggestOccurenceIndex = 0;

            try
            {
                //get 10 random numbers
                drawnNumbers = CreateNumber(30);

                for (int i = 0; i < drawnNumbers.Length; i++)
                {
                    countNumbers = 0;
                    
                    //count how many times this number occurs
                    for (int i1 = 0; i1 < drawnNumbers.Length; i1++)
                    {
                        if(drawnNumbers[i]==drawnNumbers[i1])
                        {
                            countNumbers += 1;
                        }
                    }
                    //if current count is bigger than biggest occurence
                    //save
                    if (countNumbers == biggestOccurence)
                    {
                        //if equal get lowest number
                        if (drawnNumbers[biggestOccurenceIndex] > drawnNumbers[i])
                        {
                            //change index to the current number
                            //as the one saved before is greater
                            biggestOccurence = countNumbers;
                            biggestOccurenceIndex = i;
                        }
                        //if previously saved is lower
                        //then leave it as it is, as we want the lowest number
                        
                    }
                    else if (countNumbers > biggestOccurence)
                    {
                        biggestOccurence = countNumbers;
                        biggestOccurenceIndex = i;
                    }


                }

                

                //retyrn the lowest number that occurs the most times
                return drawnNumbers[biggestOccurenceIndex];



            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);
                return -1;
            }


        }

        /// <summary>
        /// after wrong wire cut
        /// reshuffle moves themselves before reshuffling wires
        /// so each time there is a different shuffle
        /// </summary>
        private static void ReshuffleMoves()
        {
            //declare
            int skipIndex=-1;
            Util.Helpers.PublicEnums.WireShuffleType shuffleType;

            try
            {
                
                        for (int i = 0; i < World.WorldManager.BombInstanceBeingDefused.Shuffle.Turns.Count; i++)
                        {
                            for (int i1 = 0; i1 < World.WorldManager.BombInstanceBeingDefused.Shuffle.Turns[i].Moves.Count; i1++)
                            {
                                if (skipIndex != i1)
                                {
                                    //save shuffle type
                                    shuffleType = World.WorldManager.BombInstanceBeingDefused.Shuffle.Turns[i].Moves[i1].MoveType;
                                    //assign move type of next move to ths one (if exist)
                                    if (i1 + 1 <= World.WorldManager.BombInstanceBeingDefused.Shuffle.Turns[i].Moves.Count - 1)
                                    {
                                        World.WorldManager.BombInstanceBeingDefused.Shuffle.Turns[i].Moves[i1].MoveType = World.WorldManager.BombInstanceBeingDefused.Shuffle.Turns[i].Moves[i1 + 1].MoveType;
                                        World.WorldManager.BombInstanceBeingDefused.Shuffle.Turns[i].Moves[i1 + 1].MoveType = shuffleType;
                                        skipIndex = i1 + 1;
                                    }


                                }
                                else
                                {
                                    skipIndex = -1;
                                    continue;
                                }


                            }


                        }

                    
                
                



            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);
                return;
            }

        }

        #endregion


        /// <summary>
        /// create a list of randomly generated numbers
        /// </summary>
        /// <param name="length"></param>
        /// <returns></returns>
        public static int[] CreateNumber(int length)
        {
            Random random = new Random();
            int[] digits = new int[length];
            for (int i = 0; i < length - 1; i++)
            {
                digits[i] = random.Next(20);
            }
            int sum = 0;
            bool alt = true;
            for (int i = length - 2; i >= 0; i--)
            {
                int temp = digits[i];
                if (alt)
                {
                    temp *= 2;
                    if (temp > 9)
                    {
                        temp -= 9; //równoważne dodaniu cyfr do siebie np. 1+6 = 7, 16-9 = 7
                    }
                }
                sum += temp;
                alt = !alt;
            }
            int modulo = sum % 10;
            if (modulo > 0)
            {
                modulo = 10 - modulo;
            }
            digits[length - 1] = modulo;
            return digits;
        }

        /// <summary>
        /// show wires that will be used for defuse
        /// </summary>
        public static void PrepareDefusingWires()
        {
            try
            {

              

                //get all details of the bomb by id from beingDefusedBomb in world manager
             
                //if wires shown, do nothing
                if (PrepCompleted)
                {
                    return;
                }

                if (!_TexturesObtained)
                {
                    _PowerUpEmptySlotTexture=Util.Cache.GetTexture("powerUpEmptySlot").Text2D;
                    _PowerUpHUDTexture=Util.Cache.GetTexture("PowerUpHUD").Text2D;
                    _Heat3Texture = Util.Cache.GetTexture("heat3").Text2D;
                    _HeatTexture = Util.Cache.GetTexture("heat1").Text2D;
                    _WireSlotEmptyTexture=Util.Cache.GetTexture("WireSlotEmpty").Text2D;
                    _CancelButtonTexture = Util.Cache.GetTexture("button1").Text2D;
                    _Heat0Texture = Util.Cache.GetTexture("heat").Text2D;

                    _TexturesObtained = true;
                }

                //set pos for cancel button pos ,only once
                if (!_CancelButtonPosSet)
                {
                    _CancelButtonPos = new int[] { Util.Cache.GraphicsDevice.Viewport.Width - World.WorldManager.WorldConfig.BombDefusingCancelButtonWidth, 20 };

                    _CancelButtonPosSet = true;
                }


                //misc items
                //RESET
                BombFailedInformationAlphaRatio = 0.2f;
                BombFailedInformationAlphaIncrementor = .01050f;
                _HeatRectCreated = false;
                 _HeatRectY=-1;
                 _HeatRectHeight = -1;
                _AllPositionsHaveBeenSet = false;
                _HeatRectHeightModifier = 0;
                _HeatHidden = false;
                _HeatLvl2Inited = false;
              
         
                //get wire colors of the bomb
               
                        //set _time to subtract so later on we don't have to loop agian
                        //_TimeToSubtractOnBombFail = Levels.LevelManager.CurrentMap.AvailableBombs[i].TimeToSubtractOnBombFailed;

                        //loop through wires and assign random IDs , which is basically a place where it'g oging to be displayed
                        for (int w = 0; w < World.WorldManager.BombInstanceBeingDefused.Wires.Count; w++)
                        {
                           
                            //assign random id
                            World.WorldManager.BombInstanceBeingDefused.Wires[w].ID = _AssignRandomWireID(World.WorldManager.BombInstanceBeingDefused.Difficulty, World.WorldManager.BombInstanceBeingDefused.Wires[w], World.WorldManager.BombInstanceBeingDefused.Wires.Count, w);
                        }

                       
                 

                SetDefusingWire();
                
                //set wires shown to true
                PrepCompleted = true;
            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);
                return;
            }


        }

        /// <summary>
        /// Choose a random position
        /// that did not was used in 2 last sessions
        /// from a provided list of positions
        /// </summary>
        /// <returns></returns>
        public static Vector2 ChooseRandomBombPosition()
        {
            try
            {

                return new Vector2(-1, -1);
            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);
                return new Vector2(-1, -1);
            }
        }

        /// <summary>
        /// if player tapped on 1 of the wires,
        /// then uncover the one that is tapped on
        /// if found-add points 
        /// if not found-shuffle again
        /// </summary>
        /// <param name="tapPos"></param>
        public static void IsPlayerCuttingTheWire(Vector2 tapPos)
        {
         
            try
            {
                //if showing bomb fail animation, don't let player do any action
                if (ShowingBombFailInformation)
                {
                    return;
                }

                //can be done only if wiresCovered, and shuffle is done
                if (CoverWires && ShuffleDone)
                {
                  
                            //loop throug wires
                    for (int wI = 0; wI < World.WorldManager.BombInstanceBeingDefused.Wires.Count; wI++)
                            {
                                if (((tapPos.X > World.WorldManager.BombInstanceBeingDefused.Wires[wI].CurrentPosition.X) && (tapPos.X < World.WorldManager.BombInstanceBeingDefused.Wires[wI].CurrentPosition.X + World.WorldManager.BombInstanceBeingDefused.Wires[wI].Width)) && ((tapPos.Y > World.WorldManager.BombInstanceBeingDefused.Wires[wI].CurrentPosition.Y) && (tapPos.Y < World.WorldManager.BombInstanceBeingDefused.Wires[wI].CurrentPosition.Y + World.WorldManager.BombInstanceBeingDefused.Wires[wI].Height)))
                                {

                                    //set player cutting so it's shown
                                    World.WorldManager.BombInstanceBeingDefused.Wires[wI].PlayerCutting = true; 
                                    //change wire heat rect modifier to x to make the heat shrink
                                    _HeatRectHeightModifier = 3;
                                   
                             

                                    //determine result of defusing
                                    if (World.WorldManager.BombInstanceBeingDefused.Wires[wI].DefusingWire)
                                    {
                                        //award points
                                        BombPass = true;
                                        BombFail = false;
                                        //subtract 1 attempt
                                        NumberOfAttempts -= 1;

                                    }
                                    else
                                    {
                                        //reshuffle
                                        BombFail = true;
                                        _StartShuffleSet = false;//essiential to make wires reshuffle
                                        World.WorldManager.TimeSubtracted = false;
                                        //reset alpha dissolving ratio
                                        BombFailedInformationAlphaRatio = 0.2f;
                                        //subtract 1 attempt
                                        NumberOfAttempts -= 1;
                                        //WorldManager.SaveBombTries(WorldManager.BombBeingDefused, NumberOfAttempts);
                                        //save bomb state for the map
                                        StorageManager.SaveBombStateForTheMap();
                                        //set this to false to make sure that information is showed(that wrong wire cut)
                                        _BombFailInformationShowed = false;
                                        //reset shuffle move counter
                                        ShuffleMoveNumber = 0;
                                        //World.WorldManager.WiresShown = false;
                                        //World.WorldManager.ElapsedDefusingWireGracePeriod = -1;
                                        BombPass = false;




                                       

                                    }
                                   

                                    break;
                                }
                            }
                        
                    
                }


           



            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);
                return;
            }


        }

        /// <summary>
        /// reset everything
        /// </summary>
        public static void ResetBombFields()
        {
            try
            {
                #region properties
                PrepCompleted = false;
                StartShuffle = false;
                TimeElapsedSinceWiresDrawn = 0;
                CoverWires = false;
                ShuffleDone = false;
                BombPass = false;
                BombFail = false;
                NumberOfAttempts = 3;
                ShowingBombFailInformation = false;
                #endregion

                #region public fields
                BombFailedInformationAlphaRatio = 0;
                BombFailedInformationAlphaIncrementor = 0;
                ShowingBombFailedInfo1 = false;
                ShuffleMoveNumber = 0;
                DrawBombHeat = false;
                WiresRect = new Rectangle();
                #endregion


                _AssignedIDs = new List<int>();
                _DefusingWireChosen = false;
                //private static double _TimeToSubtractOnBombFail;



                //SHUFFLING
                _WireAOriginalPosition = new Vector2();
                _WireBOriginalPosition = new Vector2();
                _WireAFinishedShuffling = false;
                _WireBFinishedShuffling = false;
                _WireColorA = string.Empty;
                _WireColorB = string.Empty;
                Shuffling = false;
                _StartShuffleSet = false;
                //after wire cut (pass or fail)
                _BombPassProcessed = false;
                _ShowingBombFailedInfo1set = false;
                _BombFailInformationShowed = false;
                _AllPositionsHaveBeenSet = false;
                //used for drawing the heat:
                _HeatRectY =- 1;
                _HeatRectHeight = -1;
                _HeatRectHeightModifier = -1;
                _HeatHidden = false;
                _HeatLvl2Inited = false;

                _HeatRectCreated = false;


                _HeatPowerUpHUD = new Rectangle();
                _HeatPowerUpHUDSmall = new Rectangle();

                //powerups
                _PowerUpsDrawn = false;

                //cancel button
                _CancelButtonPosSet = false;
                _CancelButtonPos = null;


                _TexturesObtained = false;
                _WireSlotEmptyTexture = null;
                _PowerUpHUDTexture = null;
                _PowerUpEmptySlotTexture = null;
                _Heat3Texture = null;
                _HeatTexture = null;
                _Heat0Texture = null;
                _CancelButtonTexture = null;




            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);
                return;
            }
        }

        /// <summary>
        /// Is player canceling the defusing?
        /// if yes, then save number of tries and exit
        /// </summary>
        /// <param name="tapPos"></param>
        public static void IsPlayerCancelingTheDefusing(Vector2 tapPos)
        {
            try
            {
                if (_CancelButtonPosSet)
                {
                    if (ShuffleDone) //cancel button works only when shuffle is done
                    {
                        if ((tapPos.X > _CancelButtonPos[0] && tapPos.X < (_CancelButtonPos[0] + WorldManager.WorldConfig.BombDefusingCancelButtonWidth)) && (tapPos.Y > _CancelButtonPos[1] && (tapPos.Y < _CancelButtonPos[1] + WorldManager.WorldConfig.BombDefusingCancelButtonHeight)))
                        {

                            //take away 1 try
                            NumberOfAttempts -= 1;

                            //save tries
                            WorldManager.SaveBombTries(WorldManager.BombBeingDefused, NumberOfAttempts);

                            //cancel

                            DrawBombHeat = false;
                            _HeatRectCreated = false;
                            BombPass = true;
                            BombFail = false;
                            _AssignedIDs = null;

                            //cleanup
                            PrepCompleted = false;
                            StartShuffle = false;
                            TimeElapsedSinceWiresDrawn = -1;
                            CoverWires = true;
                            ShuffleDone = false;
                            ShowingBombFailInformation = false;
                            ShuffleMoveNumber = 0;
                            DrawBombHeat = false;
                            ShowingBombFailedInfo1 = false;
                            Shuffling = false;
                            _StartShuffleSet = false;
                            _WireAFinishedShuffling = false;
                            _WireBFinishedShuffling = false;
                            _BombPassProcessed = false;
                            _BombFailInformationShowed = false;
                            _AllPositionsHaveBeenSet = false;
                            World.WorldManager.BombInstanceBeingDefused.PositionsSetCT = 0;
                            World.WorldManager.WiresShown = false;
                            World.WorldManager.ElapsedDefusingWireGracePeriod = -1;
                            

                            foreach (Util.Classes.BombWire bw in World.WorldManager.BombInstanceBeingDefused.Wires)
                            {
                                bw.DefusingWire = false;
                                bw.CurrentPositionAssigned = false;
                                bw.PlayerCutting = false;
                                
                            }
                         
                            //boomb not being defused anymore
                            World.WorldManager.IsDefusingBomb = false;
                            World.WorldManager.BombBeingDefused = null;
                            World.WorldManager.BombInstanceBeingDefused = null;

                        }
                    }


                }



            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);
                return;
            }
        }

        /// <summary>
        /// shuffle wires
        /// </summary>
        public static void Shuffle()
        {
            //declare
            int movesCount=0;
           

            try
            {
                


                DrawBombHeat = true;

                for (int i = 0; i < WorldManager.BombInstanceBeingDefused.Shuffle.Turns.Count; i++)
                {
                    //for (int i1 = 0; i1 < bomb.Shuffle.Turns[i].Moves.Count; i1++)
                    //{

                    //set moves count
                    movesCount = WorldManager.BombInstanceBeingDefused.Shuffle.Turns[i].Moves.Count;

                    if (ShuffleMoveNumber > WorldManager.BombInstanceBeingDefused.Shuffle.Turns[i].Moves.Count)
                    {
                        return;
                    }

                    switch (WorldManager.BombInstanceBeingDefused.Shuffle.Turns[i].Moves[ShuffleMoveNumber].MoveType)
                        {
                            case Util.Helpers.PublicEnums.WireShuffleType.oneTwo:
                                {
                                    //update position of wire 0 and 1

                                    for (int wI = 0; wI < WorldManager.BombInstanceBeingDefused.Wires.Count; wI++)
                                    {
                                        #region Wire A

                                        if (WorldManager.BombInstanceBeingDefused.Wires[wI].ID == 0)
                                        {
                                            

                                            //moving wire 0 to position of wire 1
                                            if (!Shuffling) //if not shuffling save original position
                                            {
                                                _WireAOriginalPosition = WorldManager.BombInstanceBeingDefused.Wires[wI].CurrentPosition;
                                                _WireColorA = WorldManager.BombInstanceBeingDefused.Wires[wI].Color;
                                                _WireAFinishedShuffling = false;
                                                 
                                                
                                            }
                                            else
                                            {


                                                //if shuffling done, continue ;do nothing here do not shuffle anymore
                                                if (_WireAFinishedShuffling && _WireBFinishedShuffling || _WireColorA != WorldManager.BombInstanceBeingDefused.Wires[wI].Color)
                                                {
                                                    continue;
                                                }

                                                //shuffle
                                                //now, shuffling (only if current position X is not yet, original pos of wireB (because we are moving wireA to pos of wire B)
                                                if (_WireBOriginalPosition.X > WorldManager.BombInstanceBeingDefused.Wires[wI].CurrentPosition.X)
                                                {
                                                    WorldManager.BombInstanceBeingDefused.Wires[wI].CurrentPosition.X += (float)WorldManager.BombInstanceBeingDefused.Shuffle.ShuffleSpeed;
                                                }
                                                else 
                                                {

                                                    WorldManager.BombInstanceBeingDefused.Wires[wI].CurrentPosition.X = _WireBOriginalPosition.X;
                                                    _WireAFinishedShuffling = true;
                                                    
                                                    //replace IDs: wireA ID is now wireB ID and vice verce
                                                    WorldManager.BombInstanceBeingDefused.Wires[wI].ID = 1;
                                                
                                                }


                                            }

                                        }
                                        #endregion

                                        #region Wire B


                                        if (WorldManager.BombInstanceBeingDefused.Wires[wI].ID == 1)
                                        {
                                           

                                            //moving wire 0 to position of wire 1
                                            if (!Shuffling) //if not shuffling save original position
                                            {
                                                _WireBOriginalPosition = WorldManager.BombInstanceBeingDefused.Wires[wI].CurrentPosition;
                                                _WireColorB = WorldManager.BombInstanceBeingDefused.Wires[wI].Color;
                                                _WireBFinishedShuffling = false;
                                            }
                                            else
                                            {
                                                //if shuffling done, continue ;do nothing here do not shuffle anymore
                                                if (_WireAFinishedShuffling && _WireBFinishedShuffling || _WireColorB != WorldManager.BombInstanceBeingDefused.Wires[wI].Color)
                                                {
                                                    continue;
                                                }

                                                //shuffle
                                                //now, shuffling (only if current position X is not yet, original pos of wireA (because we are moving wireB to pos of wire A)
                                                if (_WireAOriginalPosition.X < WorldManager.BombInstanceBeingDefused.Wires[wI].CurrentPosition.X)
                                                {
                                                    WorldManager.BombInstanceBeingDefused.Wires[wI].CurrentPosition.X -= (float)WorldManager.BombInstanceBeingDefused.Shuffle.ShuffleSpeed;

                                                }
                                                else
                                                {



                                                    WorldManager.BombInstanceBeingDefused.Wires[wI].CurrentPosition.X = _WireAOriginalPosition.X;
                                                    _WireBFinishedShuffling = true;
                                                    //replace IDs: wireA ID is now wireB ID and vice verce
                                                    WorldManager.BombInstanceBeingDefused.Wires[wI].ID = 0;
                                                }
                                                
                                            }

                                        }


                                        #endregion

                                    }


                                    break;
                                }
                            case Util.Helpers.PublicEnums.WireShuffleType.TwoThree:
                                {

                                    //update position of wire 1 an 2

                                    for (int wI = 0; wI < WorldManager.BombInstanceBeingDefused.Wires.Count; wI++)
                                    {
                                        #region Wire A

                                        if (WorldManager.BombInstanceBeingDefused.Wires[wI].ID == 1)
                                        {
                                          

                                            //moving wire 0 to position of wire 1
                                            if (!Shuffling) //if not shuffling save original position
                                            {
                                                _WireAOriginalPosition = WorldManager.BombInstanceBeingDefused.Wires[wI].CurrentPosition;
                                                _WireColorA = WorldManager.BombInstanceBeingDefused.Wires[wI].Color;
                                                _WireAFinishedShuffling = false;


                                            }
                                            else
                                            {
                                                //if shuffling done, continue ;do nothing here do not shuffle anymore
                                                if (_WireAFinishedShuffling && _WireBFinishedShuffling || _WireColorA != WorldManager.BombInstanceBeingDefused.Wires[wI].Color)
                                                {
                                                    continue;
                                                }

                                                //shuffle
                                                //now, shuffling (only if current position X is not yet, original pos of wireB (because we are moving wireA to pos of wire B)
                                                if (_WireBOriginalPosition.X > WorldManager.BombInstanceBeingDefused.Wires[wI].CurrentPosition.X)
                                                {
                                                    WorldManager.BombInstanceBeingDefused.Wires[wI].CurrentPosition.X += (float)WorldManager.BombInstanceBeingDefused.Shuffle.ShuffleSpeed;
                                                }
                                                else
                                                {

                                                    WorldManager.BombInstanceBeingDefused.Wires[wI].CurrentPosition.X = _WireBOriginalPosition.X;
                                                    _WireAFinishedShuffling = true;
                                                    //replace IDs: wireA ID is now wireB ID and vice verce
                                                    WorldManager.BombInstanceBeingDefused.Wires[wI].ID = 2;

                                                }


                                            }

                                        }
                                        #endregion

                                        #region Wire B


                                        if (WorldManager.BombInstanceBeingDefused.Wires[wI].ID == 2)
                                        {
                                            

                                            //moving wire 0 to position of wire 1
                                            if (!Shuffling) //if not shuffling save original position
                                            {
                                                _WireBOriginalPosition = WorldManager.BombInstanceBeingDefused.Wires[wI].CurrentPosition;
                                                _WireColorB = WorldManager.BombInstanceBeingDefused.Wires[wI].Color;
                                                _WireBFinishedShuffling = false;
                                            }
                                            else
                                            {
                                                //if shuffling done, continue ;do nothing here do not shuffle anymore
                                                if (_WireAFinishedShuffling && _WireBFinishedShuffling || _WireColorB != WorldManager.BombInstanceBeingDefused.Wires[wI].Color)
                                                {
                                                    continue;
                                                }

                                                //shuffle
                                                //now, shuffling (only if current position X is not yet, original pos of wireA (because we are moving wireB to pos of wire A)
                                                if (_WireAOriginalPosition.X < WorldManager.BombInstanceBeingDefused.Wires[wI].CurrentPosition.X)
                                                {
                                                    WorldManager.BombInstanceBeingDefused.Wires[wI].CurrentPosition.X -= (float)WorldManager.BombInstanceBeingDefused.Shuffle.ShuffleSpeed;

                                                }
                                                else
                                                {

                                                    WorldManager.BombInstanceBeingDefused.Wires[wI].CurrentPosition.X = _WireAOriginalPosition.X;
                                                    _WireBFinishedShuffling = true;
                                                    //replace IDs: wireA ID is now wireB ID and vice verce
                                                    WorldManager.BombInstanceBeingDefused.Wires[wI].ID = 1;
                                                }

                                            }

                                        }


                                        #endregion

                                    }



                                    break;
                                }
                            case Util.Helpers.PublicEnums.WireShuffleType.FourFive:
                                {
                                    //update position of wire 3 an 4

                                    for (int wI = 0; wI < WorldManager.BombInstanceBeingDefused.Wires.Count; wI++)
                                    {
                                        #region Wire A

                                        if (WorldManager.BombInstanceBeingDefused.Wires[wI].ID == 2)
                                        {


                                            //moving wire 0 to position of wire 1
                                            if (!Shuffling) //if not shuffling save original position
                                            {
                                                _WireAOriginalPosition = WorldManager.BombInstanceBeingDefused.Wires[wI].CurrentPosition;
                                                _WireColorA = WorldManager.BombInstanceBeingDefused.Wires[wI].Color;
                                                _WireAFinishedShuffling = false;


                                            }
                                            else
                                            {
                                                //if shuffling done, continue ;do nothing here do not shuffle anymore
                                                if (_WireAFinishedShuffling && _WireBFinishedShuffling || _WireColorA != WorldManager.BombInstanceBeingDefused.Wires[wI].Color)
                                                {
                                                    continue;
                                                }

                                                //shuffle
                                                //now, shuffling (only if current position X is not yet, original pos of wireB (because we are moving wireA to pos of wire B)
                                                if (_WireBOriginalPosition.X > WorldManager.BombInstanceBeingDefused.Wires[wI].CurrentPosition.X)
                                                {
                                                    WorldManager.BombInstanceBeingDefused.Wires[wI].CurrentPosition.X += (float)WorldManager.BombInstanceBeingDefused.Shuffle.ShuffleSpeed;
                                                }
                                                else
                                                {

                                                    WorldManager.BombInstanceBeingDefused.Wires[wI].CurrentPosition.X = _WireBOriginalPosition.X;
                                                    _WireAFinishedShuffling = true;
                                                    //replace IDs: wireA ID is now wireB ID and vice verce
                                                    WorldManager.BombInstanceBeingDefused.Wires[wI].ID = 3;

                                                }


                                            }

                                        }
                                        #endregion

                                        #region Wire B


                                        if (WorldManager.BombInstanceBeingDefused.Wires[wI].ID == 3)
                                        {


                                            //moving wire 0 to position of wire 1
                                            if (!Shuffling) //if not shuffling save original position
                                            {
                                                _WireBOriginalPosition = WorldManager.BombInstanceBeingDefused.Wires[wI].CurrentPosition;
                                                _WireColorB = WorldManager.BombInstanceBeingDefused.Wires[wI].Color;
                                                _WireBFinishedShuffling = false;
                                            }
                                            else
                                            {
                                                //if shuffling done, continue ;do nothing here do not shuffle anymore
                                                if (_WireAFinishedShuffling && _WireBFinishedShuffling || _WireColorB != WorldManager.BombInstanceBeingDefused.Wires[wI].Color)
                                                {
                                                    continue;
                                                }

                                                //shuffle
                                                //now, shuffling (only if current position X is not yet, original pos of wireA (because we are moving wireB to pos of wire A)
                                                if (_WireAOriginalPosition.X < WorldManager.BombInstanceBeingDefused.Wires[wI].CurrentPosition.X)
                                                {
                                                    WorldManager.BombInstanceBeingDefused.Wires[wI].CurrentPosition.X -= (float)WorldManager.BombInstanceBeingDefused.Shuffle.ShuffleSpeed;

                                                }
                                                else
                                                {

                                                    WorldManager.BombInstanceBeingDefused.Wires[wI].CurrentPosition.X = _WireAOriginalPosition.X;
                                                    _WireBFinishedShuffling = true;
                                                    //replace IDs: wireA ID is now wireB ID and vice verce
                                                    WorldManager.BombInstanceBeingDefused.Wires[wI].ID = 2;
                                                }

                                            }

                                        }


                                        #endregion

                                    }


                                    break;
                                }
                            case Util.Helpers.PublicEnums.WireShuffleType.FiveSix:
                                {
                                    //update position of wire 4 an 5

                                    for (int wI = 0; wI < WorldManager.BombInstanceBeingDefused.Wires.Count; wI++)
                                    {
                                        #region Wire A

                                        if (WorldManager.BombInstanceBeingDefused.Wires[wI].ID == 3)
                                        {


                                            //moving wire 0 to position of wire 1
                                            if (!Shuffling) //if not shuffling save original position
                                            {
                                                _WireAOriginalPosition = WorldManager.BombInstanceBeingDefused.Wires[wI].CurrentPosition;
                                                _WireColorA = WorldManager.BombInstanceBeingDefused.Wires[wI].Color;
                                                _WireAFinishedShuffling = false;


                                            }
                                            else
                                            {
                                                //if shuffling done, continue ;do nothing here do not shuffle anymore
                                                if (_WireAFinishedShuffling && _WireBFinishedShuffling || _WireColorA != WorldManager.BombInstanceBeingDefused.Wires[wI].Color)
                                                {
                                                    continue;
                                                }

                                                //shuffle
                                                //now, shuffling (only if current position X is not yet, original pos of wireB (because we are moving wireA to pos of wire B)
                                                if (_WireBOriginalPosition.X > WorldManager.BombInstanceBeingDefused.Wires[wI].CurrentPosition.X)
                                                {
                                                    WorldManager.BombInstanceBeingDefused.Wires[wI].CurrentPosition.X += (float)WorldManager.BombInstanceBeingDefused.Shuffle.ShuffleSpeed;
                                                }
                                                else
                                                {

                                                    WorldManager.BombInstanceBeingDefused.Wires[wI].CurrentPosition.X = _WireBOriginalPosition.X;
                                                    _WireAFinishedShuffling = true;
                                                    //replace IDs: wireA ID is now wireB ID and vice verce
                                                    WorldManager.BombInstanceBeingDefused.Wires[wI].ID = 4;

                                                }


                                            }

                                        }
                                        #endregion

                                        #region Wire B


                                        if (WorldManager.BombInstanceBeingDefused.Wires[wI].ID == 4)
                                        {


                                            //moving wire 0 to position of wire 1
                                            if (!Shuffling) //if not shuffling save original position
                                            {
                                                _WireBOriginalPosition = WorldManager.BombInstanceBeingDefused.Wires[wI].CurrentPosition;
                                                _WireColorB = WorldManager.BombInstanceBeingDefused.Wires[wI].Color;
                                                _WireBFinishedShuffling = false;
                                            }
                                            else
                                            {
                                                //if shuffling done, continue ;do nothing here do not shuffle anymore
                                                if (_WireAFinishedShuffling && _WireBFinishedShuffling || _WireColorB != WorldManager.BombInstanceBeingDefused.Wires[wI].Color)
                                                {
                                                    continue;
                                                }

                                                //shuffle
                                                //now, shuffling (only if current position X is not yet, original pos of wireA (because we are moving wireB to pos of wire A)
                                                if (_WireAOriginalPosition.X < WorldManager.BombInstanceBeingDefused.Wires[wI].CurrentPosition.X)
                                                {
                                                    WorldManager.BombInstanceBeingDefused.Wires[wI].CurrentPosition.X -= (float)WorldManager.BombInstanceBeingDefused.Shuffle.ShuffleSpeed;

                                                }
                                                else
                                                {

                                                    WorldManager.BombInstanceBeingDefused.Wires[wI].CurrentPosition.X = _WireAOriginalPosition.X;
                                                    _WireBFinishedShuffling = true;
                                                    //replace IDs: wireA ID is now wireB ID and vice verce
                                                    WorldManager.BombInstanceBeingDefused.Wires[wI].ID = 3;
                                                }

                                            }

                                        }


                                        #endregion

                                    }

                                    break;
                                }
                            case Util.Helpers.PublicEnums.WireShuffleType.oneOne:
                                {
                                    //update position of wire 1 an 6
                                    //shuffle up->down


                                    for (int wI = 0; wI < WorldManager.BombInstanceBeingDefused.Wires.Count; wI++)
                                    {
                                        #region Wire A

                                        if (WorldManager.BombInstanceBeingDefused.Wires[wI].ID == 1)
                                        {


                                            //moving wire 0 to position of wire 1
                                            if (!Shuffling) //if not shuffling save original position
                                            {
                                                _WireAOriginalPosition = WorldManager.BombInstanceBeingDefused.Wires[wI].CurrentPosition;
                                                _WireColorA = WorldManager.BombInstanceBeingDefused.Wires[wI].Color;
                                                _WireAFinishedShuffling = false;


                                            }
                                            else
                                            {
                                                //if shuffling done, continue ;do nothing here do not shuffle anymore
                                                if (_WireAFinishedShuffling && _WireBFinishedShuffling || _WireColorA != WorldManager.BombInstanceBeingDefused.Wires[wI].Color)
                                                {
                                                    continue;
                                                }

                                                //shuffle
                                                //now, shuffling (only if current position X is not yet, original pos of wireB (because we are moving wireA to pos of wire B)
                                                if (_WireBOriginalPosition.Y < WorldManager.BombInstanceBeingDefused.Wires[wI].CurrentPosition.Y)
                                                {
                                                    WorldManager.BombInstanceBeingDefused.Wires[wI].CurrentPosition.Y -= (float)WorldManager.BombInstanceBeingDefused.Shuffle.ShuffleSpeed;
                                                }
                                                else
                                                {

                                                    WorldManager.BombInstanceBeingDefused.Wires[wI].CurrentPosition.Y = _WireBOriginalPosition.Y;
                                                    _WireAFinishedShuffling = true;
                                                    //replace IDs: wireA ID is now wireB ID and vice verce
                                                    WorldManager.BombInstanceBeingDefused.Wires[wI].ID = 5;

                                                }


                                            }

                                        }
                                        #endregion

                                        #region Wire B


                                        if (WorldManager.BombInstanceBeingDefused.Wires[wI].ID == 5)
                                        {


                                            //moving wire 0 to position of wire 1
                                            if (!Shuffling) //if not shuffling save original position
                                            {
                                                _WireBOriginalPosition = WorldManager.BombInstanceBeingDefused.Wires[wI].CurrentPosition;
                                                _WireColorB = WorldManager.BombInstanceBeingDefused.Wires[wI].Color;
                                                _WireBFinishedShuffling = false;
                                            }
                                            else
                                            {
                                                //if shuffling done, continue ;do nothing here do not shuffle anymore
                                                if (_WireAFinishedShuffling && _WireBFinishedShuffling || _WireColorB != WorldManager.BombInstanceBeingDefused.Wires[wI].Color)
                                                {
                                                    continue;
                                                }

                                                //shuffle
                                                //now, shuffling (only if current position X is not yet, original pos of wireA (because we are moving wireB to pos of wire A)
                                                if (_WireAOriginalPosition.Y > WorldManager.BombInstanceBeingDefused.Wires[wI].CurrentPosition.Y)
                                                {
                                                    WorldManager.BombInstanceBeingDefused.Wires[wI].CurrentPosition.Y += (float)WorldManager.BombInstanceBeingDefused.Shuffle.ShuffleSpeed;

                                                }
                                                else
                                                {
                                                    WorldManager.BombInstanceBeingDefused.Wires[wI].CurrentPosition.Y = _WireAOriginalPosition.Y;

                                                    _WireBFinishedShuffling = true;
                                                    //replace IDs: wireA ID is now wireB ID and vice verce
                                                    WorldManager.BombInstanceBeingDefused.Wires[wI].ID = 1;
                                                }

                                            }

                                        }


                                        #endregion

                                    }


                                    break;
                                }
                            case Util.Helpers.PublicEnums.WireShuffleType.twoTwo:
                                {
                                    //update position of wire 2 an 7
                                    //shuffle up->down


                                    for (int wI = 0; wI < WorldManager.BombInstanceBeingDefused.Wires.Count; wI++)
                                    {
                                        #region Wire A

                                        if (WorldManager.BombInstanceBeingDefused.Wires[wI].ID == 2)
                                        {


                                            //moving wire 0 to position of wire 1
                                            if (!Shuffling) //if not shuffling save original position
                                            {
                                                _WireAOriginalPosition = WorldManager.BombInstanceBeingDefused.Wires[wI].CurrentPosition;
                                                _WireColorA = WorldManager.BombInstanceBeingDefused.Wires[wI].Color;
                                                _WireAFinishedShuffling = false;


                                            }
                                            else
                                            {
                                                //if shuffling done, continue ;do nothing here do not shuffle anymore
                                                if (_WireAFinishedShuffling && _WireBFinishedShuffling || _WireColorA != WorldManager.BombInstanceBeingDefused.Wires[wI].Color)
                                                {
                                                    continue;
                                                }

                                                //shuffle
                                                //now, shuffling (only if current position X is not yet, original pos of wireB (because we are moving wireA to pos of wire B)
                                                if (_WireBOriginalPosition.Y < WorldManager.BombInstanceBeingDefused.Wires[wI].CurrentPosition.Y)
                                                {
                                                    WorldManager.BombInstanceBeingDefused.Wires[wI].CurrentPosition.Y -= (float)WorldManager.BombInstanceBeingDefused.Shuffle.ShuffleSpeed;
                                                }
                                                else
                                                {

                                                    WorldManager.BombInstanceBeingDefused.Wires[wI].CurrentPosition.Y = _WireBOriginalPosition.Y;
                                                    _WireAFinishedShuffling = true;
                                                    //replace IDs: wireA ID is now wireB ID and vice verce
                                                    WorldManager.BombInstanceBeingDefused.Wires[wI].ID = 6;

                                                }


                                            }

                                        }
                                        #endregion

                                        #region Wire B


                                        if (WorldManager.BombInstanceBeingDefused.Wires[wI].ID == 6)
                                        {


                                            //moving wire 0 to position of wire 1
                                            if (!Shuffling) //if not shuffling save original position
                                            {
                                                _WireBOriginalPosition = WorldManager.BombInstanceBeingDefused.Wires[wI].CurrentPosition;
                                                _WireColorB = WorldManager.BombInstanceBeingDefused.Wires[wI].Color;
                                                _WireBFinishedShuffling = false;
                                            }
                                            else
                                            {
                                                //if shuffling done, continue ;do nothing here do not shuffle anymore
                                                if (_WireAFinishedShuffling && _WireBFinishedShuffling || _WireColorB != WorldManager.BombInstanceBeingDefused.Wires[wI].Color)
                                                {
                                                    continue;
                                                }

                                                //shuffle
                                                //now, shuffling (only if current position X is not yet, original pos of wireA (because we are moving wireB to pos of wire A)
                                                if (_WireAOriginalPosition.Y > WorldManager.BombInstanceBeingDefused.Wires[wI].CurrentPosition.Y)
                                                {
                                                    WorldManager.BombInstanceBeingDefused.Wires[wI].CurrentPosition.Y += (float)WorldManager.BombInstanceBeingDefused.Shuffle.ShuffleSpeed;

                                                }
                                                else
                                                {

                                                    WorldManager.BombInstanceBeingDefused.Wires[wI].CurrentPosition.Y = _WireAOriginalPosition.Y;
                                                    _WireBFinishedShuffling = true;
                                                    //replace IDs: wireA ID is now wireB ID and vice verce
                                                    WorldManager.BombInstanceBeingDefused.Wires[wI].ID = 2;
                                                }

                                            }

                                        }


                                        #endregion

                                    }

                                    break;
                                }
                            case Util.Helpers.PublicEnums.WireShuffleType.threeThree:
                                {
                                    //update position of wire 3 an 8
                                    //shuffle up->down


                                    for (int wI = 0; wI < WorldManager.BombInstanceBeingDefused.Wires.Count; wI++)
                                    {
                                        #region Wire A

                                        if (WorldManager.BombInstanceBeingDefused.Wires[wI].ID == 3)
                                        {


                                            //moving wire 0 to position of wire 1
                                            if (!Shuffling) //if not shuffling save original position
                                            {
                                                _WireAOriginalPosition = WorldManager.BombInstanceBeingDefused.Wires[wI].CurrentPosition;
                                                _WireColorA = WorldManager.BombInstanceBeingDefused.Wires[wI].Color;
                                                _WireAFinishedShuffling = false;


                                            }
                                            else
                                            {
                                                //if shuffling done, continue ;do nothing here do not shuffle anymore
                                                if (_WireAFinishedShuffling && _WireBFinishedShuffling || _WireColorA != WorldManager.BombInstanceBeingDefused.Wires[wI].Color)
                                                {
                                                    continue;
                                                }

                                                //shuffle
                                                //now, shuffling (only if current position X is not yet, original pos of wireB (because we are moving wireA to pos of wire B)
                                                if (_WireBOriginalPosition.Y < WorldManager.BombInstanceBeingDefused.Wires[wI].CurrentPosition.Y)
                                                {
                                                    WorldManager.BombInstanceBeingDefused.Wires[wI].CurrentPosition.Y -= (float)WorldManager.BombInstanceBeingDefused.Shuffle.ShuffleSpeed;
                                                }
                                                else
                                                {

                                                    WorldManager.BombInstanceBeingDefused.Wires[wI].CurrentPosition.Y = _WireBOriginalPosition.Y;
                                                    _WireAFinishedShuffling = true;
                                                    //replace IDs: wireA ID is now wireB ID and vice verce
                                                    WorldManager.BombInstanceBeingDefused.Wires[wI].ID = 7;

                                                }


                                            }

                                        }
                                        #endregion

                                        #region Wire B


                                        if (WorldManager.BombInstanceBeingDefused.Wires[wI].ID == 7)
                                        {


                                            //moving wire 0 to position of wire 1
                                            if (!Shuffling) //if not shuffling save original position
                                            {
                                                _WireBOriginalPosition = WorldManager.BombInstanceBeingDefused.Wires[wI].CurrentPosition;
                                                _WireColorB = WorldManager.BombInstanceBeingDefused.Wires[wI].Color;
                                                _WireBFinishedShuffling = false;
                                            }
                                            else
                                            {
                                                //if shuffling done, continue ;do nothing here do not shuffle anymore
                                                if (_WireAFinishedShuffling && _WireBFinishedShuffling || _WireColorB != WorldManager.BombInstanceBeingDefused.Wires[wI].Color)
                                                {
                                                    continue;
                                                }

                                                //shuffle
                                                //now, shuffling (only if current position X is not yet, original pos of wireA (because we are moving wireB to pos of wire A)
                                                if (_WireAOriginalPosition.Y > WorldManager.BombInstanceBeingDefused.Wires[wI].CurrentPosition.Y)
                                                {
                                                    WorldManager.BombInstanceBeingDefused.Wires[wI].CurrentPosition.Y += (float)WorldManager.BombInstanceBeingDefused.Shuffle.ShuffleSpeed;

                                                }
                                                else
                                                {

                                                    WorldManager.BombInstanceBeingDefused.Wires[wI].CurrentPosition.Y = _WireAOriginalPosition.Y;
                                                    _WireBFinishedShuffling = true;
                                                    //replace IDs: wireA ID is now wireB ID and vice verce
                                                    WorldManager.BombInstanceBeingDefused.Wires[wI].ID = 3;
                                                }

                                            }

                                        }


                                        #endregion

                                    }

                                    break;
                                }
                            case Util.Helpers.PublicEnums.WireShuffleType.sixSeven:
                                {
                                    //update position of wire 5 and 6

                                    for (int wI = 0; wI < WorldManager.BombInstanceBeingDefused.Wires.Count; wI++)
                                    {
                                        #region Wire A

                                        if (WorldManager.BombInstanceBeingDefused.Wires[wI].ID == 5)
                                        {


                                            //moving wire 0 to position of wire 1
                                            if (!Shuffling) //if not shuffling save original position
                                            {
                                                _WireAOriginalPosition = WorldManager.BombInstanceBeingDefused.Wires[wI].CurrentPosition;
                                                _WireColorA = WorldManager.BombInstanceBeingDefused.Wires[wI].Color;
                                                _WireAFinishedShuffling = false;


                                            }
                                            else
                                            {
                                                //if shuffling done, continue ;do nothing here do not shuffle anymore
                                                if (_WireAFinishedShuffling && _WireBFinishedShuffling || _WireColorA != WorldManager.BombInstanceBeingDefused.Wires[wI].Color)
                                                {
                                                    continue;
                                                }

                                                //shuffle
                                                //now, shuffling (only if current position X is not yet, original pos of wireB (because we are moving wireA to pos of wire B)
                                                if (_WireBOriginalPosition.X > WorldManager.BombInstanceBeingDefused.Wires[wI].CurrentPosition.X)
                                                {
                                                    WorldManager.BombInstanceBeingDefused.Wires[wI].CurrentPosition.X += (float)WorldManager.BombInstanceBeingDefused.Shuffle.ShuffleSpeed;
                                                }
                                                else
                                                {

                                                    WorldManager.BombInstanceBeingDefused.Wires[wI].CurrentPosition.X = _WireBOriginalPosition.X;
                                                    _WireAFinishedShuffling = true;
                                                    //replace IDs: wireA ID is now wireB ID and vice verce
                                                    WorldManager.BombInstanceBeingDefused.Wires[wI].ID = 6;

                                                }


                                            }

                                        }
                                        #endregion

                                        #region Wire B


                                        if (WorldManager.BombInstanceBeingDefused.Wires[wI].ID == 6)
                                        {


                                            //moving wire 0 to position of wire 1
                                            if (!Shuffling) //if not shuffling save original position
                                            {
                                                _WireBOriginalPosition = WorldManager.BombInstanceBeingDefused.Wires[wI].CurrentPosition;
                                                _WireColorB = WorldManager.BombInstanceBeingDefused.Wires[wI].Color;
                                                _WireBFinishedShuffling = false;
                                            }
                                            else
                                            {
                                                //if shuffling done, continue ;do nothing here do not shuffle anymore
                                                if (_WireAFinishedShuffling && _WireBFinishedShuffling || _WireColorB != WorldManager.BombInstanceBeingDefused.Wires[wI].Color)
                                                {
                                                    continue;
                                                }

                                                //shuffle
                                                //now, shuffling (only if current position X is not yet, original pos of wireA (because we are moving wireB to pos of wire A)
                                                if (_WireAOriginalPosition.X < WorldManager.BombInstanceBeingDefused.Wires[wI].CurrentPosition.X)
                                                {
                                                    WorldManager.BombInstanceBeingDefused.Wires[wI].CurrentPosition.X -= (float)WorldManager.BombInstanceBeingDefused.Shuffle.ShuffleSpeed;

                                                }
                                                else
                                                {

                                                    WorldManager.BombInstanceBeingDefused.Wires[wI].CurrentPosition.X = _WireAOriginalPosition.X;
                                                    _WireBFinishedShuffling = true;
                                                    //replace IDs: wireA ID is now wireB ID and vice verce
                                                    WorldManager.BombInstanceBeingDefused.Wires[wI].ID = 5;
                                                }

                                            }

                                        }


                                        #endregion

                                    }

                                    break;
                                }
                            case Util.Helpers.PublicEnums.WireShuffleType.sevenEight:
                                {
                                    //update position of wire 6 and 7

                                    for (int wI = 0; wI < WorldManager.BombInstanceBeingDefused.Wires.Count; wI++)
                                    {
                                        #region Wire A

                                        if (WorldManager.BombInstanceBeingDefused.Wires[wI].ID == 6)
                                        {


                                            //moving wire 0 to position of wire 1
                                            if (!Shuffling) //if not shuffling save original position
                                            {
                                                _WireAOriginalPosition = WorldManager.BombInstanceBeingDefused.Wires[wI].CurrentPosition;
                                                _WireColorA = WorldManager.BombInstanceBeingDefused.Wires[wI].Color;
                                                _WireAFinishedShuffling = false;


                                            }
                                            else
                                            {
                                                //if shuffling done, continue ;do nothing here do not shuffle anymore
                                                if (_WireAFinishedShuffling && _WireBFinishedShuffling || _WireColorA != WorldManager.BombInstanceBeingDefused.Wires[wI].Color)
                                                {
                                                    continue;
                                                }

                                                //shuffle
                                                //now, shuffling (only if current position X is not yet, original pos of wireB (because we are moving wireA to pos of wire B)
                                                if (_WireBOriginalPosition.X > WorldManager.BombInstanceBeingDefused.Wires[wI].CurrentPosition.X)
                                                {
                                                    WorldManager.BombInstanceBeingDefused.Wires[wI].CurrentPosition.X += (float)WorldManager.BombInstanceBeingDefused.Shuffle.ShuffleSpeed;
                                                }
                                                else
                                                {

                                                    WorldManager.BombInstanceBeingDefused.Wires[wI].CurrentPosition.X = _WireBOriginalPosition.X;
                                                    _WireAFinishedShuffling = true;
                                                    //replace IDs: wireA ID is now wireB ID and vice verce
                                                    WorldManager.BombInstanceBeingDefused.Wires[wI].ID = 7;

                                                }


                                            }

                                        }
                                        #endregion

                                        #region Wire B


                                        if (WorldManager.BombInstanceBeingDefused.Wires[wI].ID == 7)
                                        {


                                            //moving wire 0 to position of wire 1
                                            if (!Shuffling) //if not shuffling save original position
                                            {
                                                _WireBOriginalPosition = WorldManager.BombInstanceBeingDefused.Wires[wI].CurrentPosition;
                                                _WireColorB = WorldManager.BombInstanceBeingDefused.Wires[wI].Color;
                                                _WireBFinishedShuffling = false;
                                            }
                                            else
                                            {
                                                //if shuffling done, continue ;do nothing here do not shuffle anymore
                                                if (_WireAFinishedShuffling && _WireBFinishedShuffling || _WireColorB != WorldManager.BombInstanceBeingDefused.Wires[wI].Color)
                                                {
                                                    continue;
                                                }

                                                //shuffle
                                                //now, shuffling (only if current position X is not yet, original pos of wireA (because we are moving wireB to pos of wire A)
                                                if (_WireAOriginalPosition.X < WorldManager.BombInstanceBeingDefused.Wires[wI].CurrentPosition.X)
                                                {
                                                    WorldManager.BombInstanceBeingDefused.Wires[wI].CurrentPosition.X -= (float)WorldManager.BombInstanceBeingDefused.Shuffle.ShuffleSpeed;

                                                }
                                                else
                                                {

                                                    WorldManager.BombInstanceBeingDefused.Wires[wI].CurrentPosition.X = _WireAOriginalPosition.X;
                                                    _WireBFinishedShuffling = true;
                                                    //replace IDs: wireA ID is now wireB ID and vice verce
                                                    WorldManager.BombInstanceBeingDefused.Wires[wI].ID =6;
                                                }

                                            }

                                        }


                                        #endregion

                                    }

                                    break;
                                }
                           


                        }


                    //}
                }

                //set shuffling to true
                Shuffling = true;
                ShuffleDone = false;

                //if wireA and wireB are moved, then stop shuffle
                if (_WireAFinishedShuffling && _WireBFinishedShuffling)
                {
                    if (ShuffleMoveNumber == movesCount-1)
                    {
                        //Shuffling = false;
                         ShuffleDone = true;


                    }


                    World.WorldManager.TimeSubtracted = false;
                    Shuffling = false;
                    ShuffleMoveNumber += 1;
                }



            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);
                return;
            }


        }


        #region DRAWING

        /// <summary>
        /// Draw Wires
        /// when user clicks on the bomb
        /// </summary>
        public static void DrawWires(Util.Classes.BombWire wireToDraw)
        {
          
            

            try
            {

                #region draw magic

                //save current wire's position, if not set yet
                if (!wireToDraw.CurrentPositionAssigned)
                {
                    switch (World.WorldManager.BombInstanceBeingDefused.Difficulty)
                    {
                        case 3:
                            {

                                #region DIFFICULTY 3
                                switch (wireToDraw.ID)
                                {
                                    case 0:
                                        {

                                            //(((int)Util.Cache.GraphicsDevice.Viewport.Width / 2) - (int)wireToDraw.Width / 2) is the wire in the center of the screen
                                            wireToDraw.CurrentPosition.X = (((int)Util.Cache.GraphicsDevice.Viewport.Width / 2) - (int)wireToDraw.Width / 2) - ((int)wireToDraw.Width + 30);
                                            wireToDraw.CurrentPosition.Y = (((int)Util.Cache.GraphicsDevice.Viewport.Height / 2) - (int)wireToDraw.Height / 2);
                                            wireToDraw.CurrentPositionAssigned = true;

                                            break;
                                        }
                                    case 1:
                                        {

                                            wireToDraw.CurrentPosition.X = ((int)Util.Cache.GraphicsDevice.Viewport.Width / 2) - (int)wireToDraw.Width / 2;
                                            wireToDraw.CurrentPosition.Y = (((int)Util.Cache.GraphicsDevice.Viewport.Height / 2) - (int)wireToDraw.Height / 2);
                                            wireToDraw.CurrentPositionAssigned = true;




                                            break;
                                        }
                                    case 2:
                                        {
                                            wireToDraw.CurrentPosition.X = (((int)Util.Cache.GraphicsDevice.Viewport.Width / 2) - (int)wireToDraw.Width / 2) + ((int)wireToDraw.Width + 30);
                                            wireToDraw.CurrentPosition.Y = (((int)Util.Cache.GraphicsDevice.Viewport.Height / 2) - (int)wireToDraw.Height / 2);
                                            wireToDraw.CurrentPositionAssigned = true;


                                            break;
                                        }
                              



                                }
                                #endregion
                                break;
                            }
                        case 4:
                            {
                                #region DIFFICULTY 4
                                switch (wireToDraw.ID)
                                {
                                    case 0:
                                        {

                                            //(((int)Util.Cache.GraphicsDevice.Viewport.Width / 2) - (int)wireToDraw.Width / 2) is the wire in the center of the screen
                                            wireToDraw.CurrentPosition.X = (((int)Util.Cache.GraphicsDevice.Viewport.Width / 2) - (int)wireToDraw.Width / 2) - (2 * ((int)wireToDraw.Width) + 60);
                                            wireToDraw.CurrentPosition.Y = (((int)Util.Cache.GraphicsDevice.Viewport.Height / 2) - (int)wireToDraw.Height / 2);
                                            wireToDraw.CurrentPositionAssigned = true;


                                            break;
                                        }
                                    case 1:
                                        {

                                            wireToDraw.CurrentPosition.X = (((int)Util.Cache.GraphicsDevice.Viewport.Width / 2) - (int)wireToDraw.Width / 2) - ((int)wireToDraw.Width + 30);
                                            wireToDraw.CurrentPosition.Y = (((int)Util.Cache.GraphicsDevice.Viewport.Height / 2) - (int)wireToDraw.Height / 2);
                                            wireToDraw.CurrentPositionAssigned = true;




                                            break;
                                        }
                                    case 2:
                                        {
                                            wireToDraw.CurrentPosition.X = (((int)Util.Cache.GraphicsDevice.Viewport.Width / 2) - (int)wireToDraw.Width / 2) + ((int)wireToDraw.Width + 30);
                                            wireToDraw.CurrentPosition.Y = (((int)Util.Cache.GraphicsDevice.Viewport.Height / 2) - (int)wireToDraw.Height / 2);
                                            wireToDraw.CurrentPositionAssigned = true;


                                            break;
                                        }
                                    case 3:
                                        {
                                            wireToDraw.CurrentPosition.X = (((int)Util.Cache.GraphicsDevice.Viewport.Width / 2) - (int)wireToDraw.Width / 2) + (2 * ((int)wireToDraw.Width) + 60);
                                            wireToDraw.CurrentPosition.Y = (((int)Util.Cache.GraphicsDevice.Viewport.Height / 2) - (int)wireToDraw.Height / 2);
                                            wireToDraw.CurrentPositionAssigned = true;

                                            break;
                                        }
                                 



                                }
                                #endregion
                                break;
                            }
                        case 5:
                            {
                                #region DIFFICULTY 5
                                switch (wireToDraw.ID)
                                {
                                    case 0:
                                        {


                                            wireToDraw.CurrentPosition.X = (((int)Util.Cache.GraphicsDevice.Viewport.Width / 2) - (int)wireToDraw.Width / 2) - (2 * ((int)wireToDraw.Width) + 60);
                                            wireToDraw.CurrentPosition.Y = (((int)Util.Cache.GraphicsDevice.Viewport.Height / 2) - (int)wireToDraw.Height / 2);
                                            wireToDraw.CurrentPositionAssigned = true;


                                            break;
                                        }
                                    case 1:
                                        {

                                            wireToDraw.CurrentPosition.X = (((int)Util.Cache.GraphicsDevice.Viewport.Width / 2) - (int)wireToDraw.Width / 2) - ((int)wireToDraw.Width + 30);
                                            wireToDraw.CurrentPosition.Y = (((int)Util.Cache.GraphicsDevice.Viewport.Height / 2) - (int)wireToDraw.Height / 2);
                                            wireToDraw.CurrentPositionAssigned = true;




                                            break;
                                        }
                                    case 2:
                                        {
                                            wireToDraw.CurrentPosition.X = (((int)Util.Cache.GraphicsDevice.Viewport.Width / 2) - (int)wireToDraw.Width / 2);
                                            wireToDraw.CurrentPosition.Y = (((int)Util.Cache.GraphicsDevice.Viewport.Height / 2) - (int)wireToDraw.Height / 2);
                                            wireToDraw.CurrentPositionAssigned = true;


                                            break;
                                        }
                                    case 3:
                                        {
                                            wireToDraw.CurrentPosition.X = (((int)Util.Cache.GraphicsDevice.Viewport.Width / 2) - (int)wireToDraw.Width / 2) + ((int)wireToDraw.Width + 30);
                                            wireToDraw.CurrentPosition.Y = (((int)Util.Cache.GraphicsDevice.Viewport.Height / 2) - (int)wireToDraw.Height / 2);
                                            wireToDraw.CurrentPositionAssigned = true;

                                            break;
                                        }
                                    case 4:
                                        {
                                            wireToDraw.CurrentPosition.X = (((int)Util.Cache.GraphicsDevice.Viewport.Width / 2) - (int)wireToDraw.Width / 2) + (2 * ((int)wireToDraw.Width) + 60);
                                            wireToDraw.CurrentPosition.Y = (((int)Util.Cache.GraphicsDevice.Viewport.Height / 2) - (int)wireToDraw.Height / 2);
                                            wireToDraw.CurrentPositionAssigned = true;

                                            break;


                                        }
                                 



                                }
                                #endregion
                                break;
                            }
                        case 6:
                            {
                                #region DIFFICULTY 6
                                switch (wireToDraw.ID)
                                {
                                    case 0:
                                        {


                                            wireToDraw.CurrentPosition.X = (((int)Util.Cache.GraphicsDevice.Viewport.Width / 2) - (int)wireToDraw.Width / 2) - (2 * ((int)wireToDraw.Width) + 60);
                                            wireToDraw.CurrentPosition.Y = (((int)Util.Cache.GraphicsDevice.Viewport.Height / 2) - (int)wireToDraw.Height / 2);
                                            wireToDraw.CurrentPositionAssigned = true;


                                            break;
                                        }
                                    case 1:
                                        {

                                            wireToDraw.CurrentPosition.X = (((int)Util.Cache.GraphicsDevice.Viewport.Width / 2) - (int)wireToDraw.Width / 2) - ((int)wireToDraw.Width + 30);
                                            wireToDraw.CurrentPosition.Y = (((int)Util.Cache.GraphicsDevice.Viewport.Height / 2) - (int)wireToDraw.Height / 2);
                                            wireToDraw.CurrentPositionAssigned = true;




                                            break;
                                        }
                                    case 2:
                                        {
                                            wireToDraw.CurrentPosition.X = (((int)Util.Cache.GraphicsDevice.Viewport.Width / 2) - (int)wireToDraw.Width / 2);
                                            wireToDraw.CurrentPosition.Y = (((int)Util.Cache.GraphicsDevice.Viewport.Height / 2) - (int)wireToDraw.Height / 2);
                                            wireToDraw.CurrentPositionAssigned = true;


                                            break;
                                        }
                                    case 3:
                                        {
                                            wireToDraw.CurrentPosition.X = (((int)Util.Cache.GraphicsDevice.Viewport.Width / 2) - (int)wireToDraw.Width / 2) + ((int)wireToDraw.Width + 30);
                                            wireToDraw.CurrentPosition.Y = (((int)Util.Cache.GraphicsDevice.Viewport.Height / 2) - (int)wireToDraw.Height / 2);
                                            wireToDraw.CurrentPositionAssigned = true;

                                            break;
                                        }
                                    case 4:
                                        {
                                            wireToDraw.CurrentPosition.X = (((int)Util.Cache.GraphicsDevice.Viewport.Width / 2) - (int)wireToDraw.Width / 2) + (2 * ((int)wireToDraw.Width) + 60);
                                            wireToDraw.CurrentPosition.Y = (((int)Util.Cache.GraphicsDevice.Viewport.Height / 2) - (int)wireToDraw.Height / 2);
                                            wireToDraw.CurrentPositionAssigned = true;

                                            break;


                                        }
                                    case 5:
                                        {
                                            wireToDraw.CurrentPosition.X = (((int)Util.Cache.GraphicsDevice.Viewport.Width / 2) - (int)wireToDraw.Width / 2);
                                            wireToDraw.CurrentPosition.Y = (((int)Util.Cache.GraphicsDevice.Viewport.Height / 2) - (int)wireToDraw.Height / 2) - (((int)wireToDraw.Height) + 30);
                                            wireToDraw.CurrentPositionAssigned = true;

                                            break;
                                        }
                                    



                                }
                                #endregion
                                break;
                            }
                        case 7:
                            {
                                #region DIFFICULTY 7
                                switch (wireToDraw.ID)
                                {
                                    case 0:
                                        {


                                            wireToDraw.CurrentPosition.X = (((int)Util.Cache.GraphicsDevice.Viewport.Width / 2) - (int)wireToDraw.Width / 2) - (2 * ((int)wireToDraw.Width) + 60);
                                            wireToDraw.CurrentPosition.Y = (((int)Util.Cache.GraphicsDevice.Viewport.Height / 2) - (int)wireToDraw.Height / 2);
                                            wireToDraw.CurrentPositionAssigned = true;


                                            break;
                                        }
                                    case 1:
                                        {

                                            wireToDraw.CurrentPosition.X = (((int)Util.Cache.GraphicsDevice.Viewport.Width / 2) - (int)wireToDraw.Width / 2) - ((int)wireToDraw.Width + 30);
                                            wireToDraw.CurrentPosition.Y = (((int)Util.Cache.GraphicsDevice.Viewport.Height / 2) - (int)wireToDraw.Height / 2);
                                            wireToDraw.CurrentPositionAssigned = true;




                                            break;
                                        }
                                    case 2:
                                        {
                                            wireToDraw.CurrentPosition.X = (((int)Util.Cache.GraphicsDevice.Viewport.Width / 2) - (int)wireToDraw.Width / 2);
                                            wireToDraw.CurrentPosition.Y = (((int)Util.Cache.GraphicsDevice.Viewport.Height / 2) - (int)wireToDraw.Height / 2);
                                            wireToDraw.CurrentPositionAssigned = true;


                                            break;
                                        }
                                    case 3:
                                        {
                                            wireToDraw.CurrentPosition.X = (((int)Util.Cache.GraphicsDevice.Viewport.Width / 2) - (int)wireToDraw.Width / 2) + ((int)wireToDraw.Width + 30);
                                            wireToDraw.CurrentPosition.Y = (((int)Util.Cache.GraphicsDevice.Viewport.Height / 2) - (int)wireToDraw.Height / 2);
                                            wireToDraw.CurrentPositionAssigned = true;

                                            break;
                                        }
                                    case 4:
                                        {
                                            wireToDraw.CurrentPosition.X = (((int)Util.Cache.GraphicsDevice.Viewport.Width / 2) - (int)wireToDraw.Width / 2) + (2 * ((int)wireToDraw.Width) + 60);
                                            wireToDraw.CurrentPosition.Y = (((int)Util.Cache.GraphicsDevice.Viewport.Height / 2) - (int)wireToDraw.Height / 2);
                                            wireToDraw.CurrentPositionAssigned = true;

                                            break;


                                        }
                                    case 5:
                                        {
                                            wireToDraw.CurrentPosition.X = (((int)Util.Cache.GraphicsDevice.Viewport.Width / 2) - (int)wireToDraw.Width / 2) - ((int)wireToDraw.Width + 30);
                                            wireToDraw.CurrentPosition.Y = (((int)Util.Cache.GraphicsDevice.Viewport.Height / 2) - (int)wireToDraw.Height / 2) - (((int)wireToDraw.Height) + 30);
                                            wireToDraw.CurrentPositionAssigned = true;

                                            break;
                                        }
                                    case 6:
                                        {
                                            wireToDraw.CurrentPosition.X = (((int)Util.Cache.GraphicsDevice.Viewport.Width / 2) - (int)wireToDraw.Width / 2) + ((int)wireToDraw.Width + 30);
                                            wireToDraw.CurrentPosition.Y = (((int)Util.Cache.GraphicsDevice.Viewport.Height / 2) - (int)wireToDraw.Height / 2) - (((int)wireToDraw.Height) + 30);
                                            wireToDraw.CurrentPositionAssigned = true;

                                            break;
                                        }
                                   



                                }
                                #endregion
                                break;
                            }
                        case 8:
                            {

                                #region DIFFICULTY 8
                                switch (wireToDraw.ID)
                                {
                                    case 0:
                                        {


                                            wireToDraw.CurrentPosition.X = (((int)Util.Cache.GraphicsDevice.Viewport.Width / 2) - (int)wireToDraw.Width / 2) - (2 * ((int)wireToDraw.Width) + 60);
                                            wireToDraw.CurrentPosition.Y = (((int)Util.Cache.GraphicsDevice.Viewport.Height / 2) - (int)wireToDraw.Height / 2);
                                            wireToDraw.CurrentPositionAssigned = true;


                                            break;
                                        }
                                    case 1:
                                        {

                                            wireToDraw.CurrentPosition.X = (((int)Util.Cache.GraphicsDevice.Viewport.Width / 2) - (int)wireToDraw.Width / 2) - ((int)wireToDraw.Width + 30);
                                            wireToDraw.CurrentPosition.Y = (((int)Util.Cache.GraphicsDevice.Viewport.Height / 2) - (int)wireToDraw.Height / 2);
                                            wireToDraw.CurrentPositionAssigned = true;




                                            break;
                                        }
                                    case 2:
                                        {
                                            wireToDraw.CurrentPosition.X = (((int)Util.Cache.GraphicsDevice.Viewport.Width / 2) - (int)wireToDraw.Width / 2);
                                            wireToDraw.CurrentPosition.Y = (((int)Util.Cache.GraphicsDevice.Viewport.Height / 2) - (int)wireToDraw.Height / 2);
                                            wireToDraw.CurrentPositionAssigned = true;


                                            break;
                                        }
                                    case 3:
                                        {
                                            wireToDraw.CurrentPosition.X = (((int)Util.Cache.GraphicsDevice.Viewport.Width / 2) - (int)wireToDraw.Width / 2) + ((int)wireToDraw.Width + 30);
                                            wireToDraw.CurrentPosition.Y = (((int)Util.Cache.GraphicsDevice.Viewport.Height / 2) - (int)wireToDraw.Height / 2);
                                            wireToDraw.CurrentPositionAssigned = true;

                                            break;
                                        }
                                    case 4:
                                        {
                                            wireToDraw.CurrentPosition.X = (((int)Util.Cache.GraphicsDevice.Viewport.Width / 2) - (int)wireToDraw.Width / 2) + (2 * ((int)wireToDraw.Width) + 60);
                                            wireToDraw.CurrentPosition.Y = (((int)Util.Cache.GraphicsDevice.Viewport.Height / 2) - (int)wireToDraw.Height / 2);
                                            wireToDraw.CurrentPositionAssigned = true;

                                            break;


                                        }
                                    case 5:
                                        {
                                            wireToDraw.CurrentPosition.X = (((int)Util.Cache.GraphicsDevice.Viewport.Width / 2) - (int)wireToDraw.Width / 2) - ((int)wireToDraw.Width + 30);
                                            wireToDraw.CurrentPosition.Y = (((int)Util.Cache.GraphicsDevice.Viewport.Height / 2) - (int)wireToDraw.Height / 2) - (((int)wireToDraw.Height) + 30);
                                            wireToDraw.CurrentPositionAssigned = true;

                                            break;
                                        }
                                    case 6:
                                        {
                                            wireToDraw.CurrentPosition.X = (((int)Util.Cache.GraphicsDevice.Viewport.Width / 2) - (int)wireToDraw.Width / 2);
                                            wireToDraw.CurrentPosition.Y = (((int)Util.Cache.GraphicsDevice.Viewport.Height / 2) - (int)wireToDraw.Height / 2) - (((int)wireToDraw.Height) + 30);
                                            wireToDraw.CurrentPositionAssigned = true;

                                            break;
                                        }
                                    case 7:
                                        {
                                            wireToDraw.CurrentPosition.X = (((int)Util.Cache.GraphicsDevice.Viewport.Width / 2) - (int)wireToDraw.Width / 2) + ((int)wireToDraw.Width + 30);
                                            wireToDraw.CurrentPosition.Y = (((int)Util.Cache.GraphicsDevice.Viewport.Height / 2) - (int)wireToDraw.Height / 2) - (((int)wireToDraw.Height) + 30);
                                            wireToDraw.CurrentPositionAssigned = true;

                                            break;
                                        }



                                }
                                #endregion
                                break;
                            }


                        
                    }

                    World.WorldManager.BombInstanceBeingDefused.PositionsSetCT += 1;

                    //check:
                    //if positionsCT is equal to wires count, then
                    //set positionsSet flag to true
                    if (World.WorldManager.BombInstanceBeingDefused.PositionsSetCT == World.WorldManager.BombInstanceBeingDefused.Wires.Count)
                    {
                        _AllPositionsHaveBeenSet = true;
                        World.WorldManager.BombInstanceBeingDefused.PositionsSetCT = 0;
                    }
                }

                //draw
                            if (!CoverWires)
                            {

                                Util.Cache.Draw(Util.Cache.GetTexture(wireToDraw.Texture).Text2D, new Microsoft.Xna.Framework.Rectangle((int)wireToDraw.CurrentPosition.X, (int)wireToDraw.CurrentPosition.Y, (int)wireToDraw.Width, (int)wireToDraw.Height), Color.White);
                            }
                            else
                            {
                                //if player is cutting the wire , uncover it for a while
                                if (wireToDraw.PlayerCutting)
                                {
                                    Util.Cache.Draw(Util.Cache.GetTexture(wireToDraw.Texture).Text2D, new Microsoft.Xna.Framework.Rectangle((int)wireToDraw.CurrentPosition.X, (int)wireToDraw.CurrentPosition.Y, (int)wireToDraw.Width, (int)wireToDraw.Height), Color.White);
                                }
                                else
                                {
                                    Util.Cache.Draw(_WireSlotEmptyTexture, new Microsoft.Xna.Framework.Rectangle((int)wireToDraw.CurrentPosition.X, (int)wireToDraw.CurrentPosition.Y, (int)wireToDraw.Width, (int)wireToDraw.Height), Color.White);
                                }
                            }


                            #endregion

                        //draw powerups
                            DrawPowerUpsHUD();

                //draw number of attempts
                            Util.Cache.DrawString(Util.Cache.GetFont("AwardPointsFont").FontFace, "Attempts left: " + NumberOfAttempts.ToString(), new Vector2(10, 10), 20, Color.Red);

            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);
                return;
            }
        }

        /// <summary>
        /// draw power ups HUD
        /// </summary>
        public static void DrawPowerUpsHUD()
        {
            //declare
            Rectangle r;

            try
            {
                //show powerups if heat rect is created, heat is not hidden and shuffle is not taking place and if heatRectModifier is =0, otherwise 
                //hiding heat animation is on, so do not show powerups then
                if (_HeatRectCreated && !_HeatHidden && ShuffleDone && _HeatRectHeightModifier <= 0)
                {
                    r = new Rectangle((((int)Util.Cache.GraphicsDevice.Viewport.Width / 2) - 30) - 180, WiresRect.Y + WiresRect.Height + 30, 450, 150);
                    Util.Cache.Draw(_PowerUpHUDTexture, r, Color.White);
                    //create heat rects
                    _HeatPowerUpHUD = new Rectangle(r.X, r.Y + 40, r.Width, r.Height-40);
                    _HeatPowerUpHUDSmall = new Rectangle(r.X + 125, r.Y+3, 198, 40);

                    //create powerup rectangles
                    _PreparePowerupsToBeDrawn(r);
                   
                    
                    _DrawPowerUps();
                }



            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);
                return;
            }
        }


        /// <summary>
        /// draw power ups
        /// </summary>
        private static void _DrawPowerUps()
        {
            try
            {

                    //loop throug available powerups
                    //and draw
                    //forecah p in cache.powerups
                    for (int i = 0; i < World.WorldManager.Powerups.Count; i++)
                    {
                        
                        //draw
                        Util.Cache.Draw(_PowerUpEmptySlotTexture, World.WorldManager.Powerups[i].Rect, Color.White);
                        //draw count info
                        Util.Cache.DrawString(World.WorldManager.Powerups[i].FontFace, "X" + World.WorldManager.Powerups[i].Count.ToString(), World.WorldManager.Powerups[i].CountInfoTextPosition, 15, Color.Black);

                        
                    }


            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);
                return;
            }
        }

        /// <summary>
        /// dim background
        /// highlight wires and time
        /// </summary>
        public static void DrawBombDefusingHeat()
        {
            //declare
            int wiresCount = -1;

            try
            {
                if (!_AllPositionsHaveBeenSet || _HeatHidden)
                {
                    return;
                }

                

                #region wires
                if (!_HeatRectCreated)
                {


                            wiresCount = World.WorldManager.BombInstanceBeingDefused.Wires.Count;

                            //draw wires
                            for (int w = 0; w < World.WorldManager.BombInstanceBeingDefused.Wires.Count; w++)
                            {
                                if (World.WorldManager.BombInstanceBeingDefused.Wires[w].ID == 0)
                                {
                                    //create rectangle only if current position is assigned
                                    if (World.WorldManager.BombInstanceBeingDefused.Wires[w].CurrentPositionAssigned)
                                    {
                                        WiresRect = new Rectangle(-15, (int)World.WorldManager.BombInstanceBeingDefused.Wires[w].CurrentPosition.Y - 20, Util.Cache.GraphicsDevice.Viewport.Width + 30, (int)(1.5 * World.WorldManager.BombInstanceBeingDefused.Wires[w].Height));
                                        _HeatRectCreated = true;
                                        //break;
                                    }
                                }


                                //if there is wire with ID 5 it means that there are 2 levels of wires
                                //so instead of using Y from wire 0, use Y from ID 5
                                if (World.WorldManager.BombInstanceBeingDefused.Wires[w].ID == 5)
                                {
                                    if (World.WorldManager.BombInstanceBeingDefused.Wires[w].CurrentPositionAssigned)
                                    {
                                        _HeatRectY = ((int)World.WorldManager.BombInstanceBeingDefused.Wires[w].CurrentPosition.Y) - 20;
                                        _HeatRectHeight = (int)(3 * World.WorldManager.BombInstanceBeingDefused.Wires[w].Height);

                                       

                                        //break;
                                    }
                                }
                            }
                        

                    
                }
                else
                {
                    
                    //update heat rect's y and height if 2 levels of wires are on the screen
                    if (_HeatRectY > -1)
                    {
                        if (!_HeatLvl2Inited)
                        {
                            WiresRect.Y = _HeatRectY;
                            WiresRect.Height = _HeatRectHeight;
                            _HeatLvl2Inited = true;
                        }
                    }

                    //subtract x from rect's height
                    WiresRect.Height -= _HeatRectHeightModifier;
                    WiresRect.Y += _HeatRectHeightModifier;

                    //if heat rect is hidden then set flag to true
                    if (WiresRect.Height <= 0)
                    {
                        _HeatHidden = true;
                    }

                    //draw the heat
                    Util.Cache.Draw(_HeatTexture, WiresRect, Color.White);

                    //#region right
                    //Util.Cache.Draw(Util.Cache.GetTexture("heat").Text2D, new Rectangle(WiresRect.X + WiresRect.Width, WiresRect.Y, Util.Cache.GraphicsDevice.Viewport.Width - (WiresRect.X + WiresRect.Width), (Util.Cache.GraphicsDevice.Viewport.Height - WiresRect.Y)), Color.White);

                    //#endregion

                    //#region left
                    //Util.Cache.Draw(Util.Cache.GetTexture("heat").Text2D, new Rectangle(0, WiresRect.Y, WiresRect.X, (Util.Cache.GraphicsDevice.Viewport.Height - WiresRect.Y)), Color.White);

                    //#endregion

                    #region down
                    //draw greyed out background only if hiding heat is on
                    //and also if shuffle is not done (meaning that shuffling is being perfomed)
                    if (_HeatRectHeightModifier <= 0)
                    {
                        if (!ShuffleDone)
                        {
                            Util.Cache.Draw(_Heat0Texture, new Rectangle(WiresRect.X, WiresRect.Y + WiresRect.Height, WiresRect.Width, Util.Cache.GraphicsDevice.Viewport.Height - (WiresRect.Y + WiresRect.Height)), Color.White);
                        }
                    }
                    else
                    {
                        Util.Cache.Draw(_Heat0Texture, new Rectangle(WiresRect.X, WiresRect.Y + WiresRect.Height, WiresRect.Width, Util.Cache.GraphicsDevice.Viewport.Height - (WiresRect.Y + WiresRect.Height)), Color.White);
                    }

                    #endregion

                #endregion

                    #region heat up
                    Util.Cache.Draw(_Heat0Texture, new Rectangle(0, 0, Util.Cache.GraphicsDevice.Viewport.Width, WiresRect.Y), Color.White);

                    #endregion

                    //heat for powerup hud
                    #region power ups AND cancel button
                    //draw heat for powerup HUD only if shuffle is done
                    if (ShuffleDone && _HeatRectHeightModifier <= 0)
                    {

                        #region POWERUPS 

                        Util.Cache.Draw(_Heat3Texture, _HeatPowerUpHUD, Color.White);
                        Util.Cache.Draw(_Heat3Texture, _HeatPowerUpHUDSmall, Color.White);

                        #region bigRectRight
                        Util.Cache.Draw(_Heat0Texture, new Rectangle(_HeatPowerUpHUD.X + _HeatPowerUpHUD.Width, _HeatPowerUpHUD.Y, Util.Cache.GraphicsDevice.Viewport.Width - (_HeatPowerUpHUD.X + _HeatPowerUpHUD.Width), _HeatPowerUpHUD.Y + (Util.Cache.GraphicsDevice.Viewport.Height - _HeatPowerUpHUD.Y)), Color.White);

                        #endregion

                        #region bigRectLeft
                        Util.Cache.Draw(_Heat0Texture, new Rectangle(0, _HeatPowerUpHUD.Y, _HeatPowerUpHUD.X, _HeatPowerUpHUD.Y + (Util.Cache.GraphicsDevice.Viewport.Height - _HeatPowerUpHUD.Y)), Color.White);
                        #endregion

                        #region bigRectDonw
                        Util.Cache.Draw(_Heat0Texture, new Rectangle(_HeatPowerUpHUD.X, _HeatPowerUpHUD.Y + _HeatPowerUpHUD.Height, _HeatPowerUpHUD.Width, Util.Cache.GraphicsDevice.Viewport.Height - (_HeatPowerUpHUD.Y + _HeatPowerUpHUD.Height)), Color.White);
                        #endregion

                        #region smallRectRight
                        Util.Cache.Draw(_Heat0Texture, new Rectangle(_HeatPowerUpHUDSmall.X + _HeatPowerUpHUDSmall.Width, _HeatPowerUpHUDSmall.Y, Util.Cache.GraphicsDevice.Viewport.Width - (_HeatPowerUpHUDSmall.X + _HeatPowerUpHUDSmall.Width), _HeatPowerUpHUDSmall.Height), Color.White);

                        #endregion

                        #region smallRectLeft
                        Util.Cache.Draw(_Heat0Texture, new Rectangle(0, _HeatPowerUpHUDSmall.Y, _HeatPowerUpHUDSmall.X, _HeatPowerUpHUDSmall.Height), Color.White);
                        #endregion

                        #region smallRectUp
                        Util.Cache.Draw(_Heat0Texture, new Rectangle(0, WiresRect.Y + WiresRect.Height, Util.Cache.GraphicsDevice.Viewport.Width, _HeatPowerUpHUDSmall.Height), Color.White);
                        #endregion

                        #endregion

                        #region CANCEL BUTTON

                        if (_CancelButtonPosSet)
                        {
                            //button
                            Util.Cache.Draw(_CancelButtonTexture, new Rectangle(_CancelButtonPos[0], _CancelButtonPos[1], WorldManager.WorldConfig.BombDefusingCancelButtonWidth, WorldManager.WorldConfig.BombDefusingCancelButtonHeight), Color.White);
                            //Exit-write string on the button
                            Util.Cache.DrawString(Util.Cache.GetFont("AwardPointsFont").FontFace, "Exit", new Vector2(_CancelButtonPos[0] + 2, _CancelButtonPos[1] + 5), 15, Color.Black);

                        }


                        #endregion

                    }



                    #endregion

                   

                    //draw time
                    //WorldManager.DrawTimerInHeat();

                    //time
                    //#region time
                    //timeRect = new Rectangle(((int)Util.Cache.GraphicsDevice.Viewport.Width / 2) - 70, ((int)Util.Cache.GraphicsDevice.Viewport.Height / 2)-200, 150, 43);
                    //Util.Cache.Draw(Util.Cache.GetTexture("heat1").Text2D, timeRect, Color.White);

                    //#region right
                    //Util.Cache.Draw(Util.Cache.GetTexture("heat").Text2D, new Rectangle(timeRect.X + timeRect.Width, 0, Util.Cache.GraphicsDevice.Viewport.Width - (timeRect.X + timeRect.Width), (0 + WiresRect.Y)), Color.White);

                    //#endregion

                    //#region left
                    //Util.Cache.Draw(Util.Cache.GetTexture("heat").Text2D, new Rectangle(0, 0, timeRect.X, WiresRect.Y), Color.White);

                    //#endregion

                    //#region down
                    //Util.Cache.Draw(Util.Cache.GetTexture("heat").Text2D, new Rectangle(timeRect.X, timeRect.Y + timeRect.Height, timeRect.Width, WiresRect.Y - (timeRect.Y + timeRect.Height)), Color.White);

                    //#endregion

                    //#region up
                    //Util.Cache.Draw(Util.Cache.GetTexture("heat").Text2D, new Rectangle(timeRect.X, 0, timeRect.Width, timeRect.Y), Color.White);


                    //#endregion

                    //#endregion
                }
            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);
                return;
            }
        }

        /// <summary>
        /// Draw bomb pass
        /// </summary>
        public static void DrawBombPass()
        {
           
            //declare
            int pointsToAward = 0;

            try
            {
               


                if (_BombPassProcessed || !_HeatHidden)
                {
                    //if points already added,then exit
                    return;
                }

                DrawBombHeat = false;
                _HeatRectCreated = false;
              
                //Util.Cache.Draw(Util.Cache.GetTexture("BombDefused").Text2D, new Rectangle(400, 200, 60, 60), Color.White);


                //award points
                //determine points to award, it depends from in which try player defused the bomb
                if (NumberOfAttempts == 2)
                {
                    pointsToAward = Levels.LevelManager.CurrentMap.PointsForDefusingBomb1;
                }
                else if (NumberOfAttempts == 1)
                {
                    pointsToAward = Levels.LevelManager.CurrentMap.PointsForDefusingBomb2;
                }
                else if (NumberOfAttempts == 0)
                {
                    pointsToAward = Levels.LevelManager.CurrentMap.PointsForDefusingBomb3;
                }
                //award
                World.WorldManager.AwardPoints(Util.Helpers.PublicEnums.AcheivementType.BombDefused, pointsToAward, 0.001f);

                //save bomb found
                Levels.LevelManager.CurrentMap.BombDefused = true;
                //save bomb state for the map
                StorageManager.SaveBombStateForTheMap();


                BombPass = false;

                _BombPassProcessed = true;

             

                //boomb not being defused anymore
                World.WorldManager.IsDefusingBomb = false;
                World.WorldManager.BombBeingDefused = null;
                World.WorldManager.BombInstanceBeingDefused = null;

            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);
                return;
            }
        }


        /// <summary>
        /// Draw bomb pass
        /// </summary>
        public static void DrawBombFailed()
        {
            try
            {
                if (!_HeatHidden)
                {
                    return;
                }

                //show bomb failed animation first
                if (!_BombFailInformationShowed)
                {
                    //first set if ShowingBombFailedInfo1 has been set
                    if (!_ShowingBombFailedInfo1set)
                    {
                        ShowingBombFailedInfo1 = true;
                        _ShowingBombFailedInfo1set = true;
                    }
                    //draw bomb failed info
                    DrawBombFailedInfo();

                 


                }
                else
                {
                    //if 0 attempts, raise on bomb failed event
                    #region raise bomb defuse failed event

                    if (NumberOfAttempts <= 0)
                    {
                         //loop through events
                                for (int eI = 0; eI <  World.WorldManager.BombInstanceBeingDefused.Events.Count; eI++)
                                {
                                    if (World.WorldManager.BombInstanceBeingDefused.Events[eI].EventType == Util.Helpers.PublicEnums.EventType.onDefuseFailed)
                                    {
                                        EventHandler.RaiseEvent(World.WorldManager.BombInstanceBeingDefused.Events[eI]);
                                        return;
                                    }
                                }


                            
                        
                    }

                    #endregion

                    //show heat again
                    _HeatRectHeightModifier = 0;
                    _HeatHidden = false;
                    _HeatLvl2Inited = false;
                    _HeatRectCreated = false;

                    //start shuffling
                    if (!_StartShuffleSet)
                    {
                        #region remove x seconds/minutes from overall time AND make timer red for a while

                        //make timer font red
                        World.WorldManager.TimeSubtracted = true;
                        #endregion

                       
                                    

                        ShuffleDone = false;
                        StartShuffle = false;
                        _StartShuffleSet = true;
                      
                    }
                }
                

            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);
                return;
            }
        }


        /// <summary>
        /// if player chose wrong wire to defuse
        /// then show information that 1 attempt is subtracted from available attempts
        /// and time
        /// and reshuffle will happen now
        /// </summary>
        public static void DrawBombFailedInfo()
        {
            try
            {
                DrawBombHeat = false;
                ShowingBombFailInformation = true;

                //grey out the screen
                Util.Cache.Draw(Util.Cache.GetTexture("greyedOutBackground").Text2D, new Rectangle(0, 0, Util.Cache.GraphicsDevice.Viewport.Width, Util.Cache.GraphicsDevice.Viewport.Height), Color.White);
                //show attempts left:
                Util.Cache.DrawString(Util.Cache.GetFont("StencilFont").FontFace, "Attempts Left: " + NumberOfAttempts.ToString(), new Vector2((Util.Cache.GraphicsDevice.Viewport.Width / 2) + 60, (Util.Cache.GraphicsDevice.Viewport.Height/2)+100), 30, Color.Red);
                //show information how much time will be subtracted for this 65, 20
                //Util.Cache.DrawString(Util.Cache.GetFont("StencilFont").FontFace, "- " + _TimeToSubtractOnBombFail.ToString() + " seconds!", new Vector2(65, 30), 30, Color.Red);

                //if no more attempts inform player that no more attempts left...
                if (NumberOfAttempts == 0)
                {
                    Util.Cache.DrawString(Util.Cache.GetFont("StencilFont").FontFace, "Oh-oh...YOU FAILED!", new Vector2((Util.Cache.GraphicsDevice.Viewport.Width / 2) - 15, (Util.Cache.GraphicsDevice.Viewport.Height / 2) - 15), 30, Color.Lerp(new Color(255, 5, 21, 255), Color.Transparent, BombFailedInformationAlphaRatio));

                    //quit this method and raise defuse failed event
                    if (BombFailedInformationAlphaRatio >= 1)
                    {
                        ShowingBombFailInformation = false;
                        _BombFailInformationShowed = true;
                        return;
                    }
                }
                else
                {
                   

                    //show Wrong Wire!-this slowly dissolves
                    if (ShowingBombFailedInfo1)
                    {
                        Util.Cache.DrawString(Util.Cache.GetFont("StencilFont").FontFace, "Wrong Wire!", new Vector2((Util.Cache.GraphicsDevice.Viewport.Width / 2)-15, (Util.Cache.GraphicsDevice.Viewport.Height / 2)-15), 30, Color.Lerp(new Color(255, 5, 21, 255), Color.Transparent, BombFailedInformationAlphaRatio));


                        //reshuffle moves
                        ReshuffleMoves();

                        //show another string if this one dissolves
                        if (BombFailedInformationAlphaRatio >= 1)
                        {
                            ShowingBombFailedInfo1 = false;
                            //reset alpha ratio
                            BombFailedInformationAlphaRatio = 0.2f;
                        }

                    }
                    else
                    {


                        Util.Cache.DrawString(Util.Cache.GetFont("StencilFont").FontFace, "ReShuffling...", new Vector2((Util.Cache.GraphicsDevice.Viewport.Width / 2) - 15, (Util.Cache.GraphicsDevice.Viewport.Height / 2) - 15), 30, Color.Lerp(new Color(255, 5, 21, 255), Color.Transparent, BombFailedInformationAlphaRatio));


                        //quit shoiwing information when this string dissolves
                        if (BombFailedInformationAlphaRatio >= 1)
                        {
                            ShowingBombFailInformation = false;
                            _BombFailInformationShowed = true;
                            _ShowingBombFailedInfo1set = false;

                            #region hide wire that player clicked on thinking that tis was the one defusing the bomb


                            //loop throug wires
                            for (int wI1 = 0; wI1 < WorldManager.BombInstanceBeingDefused.Wires.Count; wI1++)
                            {
                                if (WorldManager.BombInstanceBeingDefused.Wires[wI1].PlayerCutting)
                                {
                                    //set to false
                                    WorldManager.BombInstanceBeingDefused.Wires[wI1].PlayerCutting = false;
                                    break;
                                }
                            }



                            World.WorldManager.WiresShown = false;
                            World.WorldManager.ElapsedDefusingWireGracePeriod = -1;
                            CoverWires = false;
                           

                            #endregion

                            return;
                        }
                    }
                }

                
            }
            catch (Exception ex)
            {
                Util.ErrorLogging.LogError(ex);
                return;
            }
        }



        #endregion

        #endregion


    }
}
